package v1

import (
	"gin-vue-admin/global"
    "gin-vue-admin/model"
    "gin-vue-admin/model/request"
    "gin-vue-admin/model/response"
    "gin-vue-admin/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

// @Tags SelectResearch
// @Summary 创建SelectResearch
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SelectResearch true "创建SelectResearch"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /selectResearch/createSelectResearch [post]
func CreateSelectResearch(c *gin.Context) {
	var selectResearch model.SelectResearch
	_ = c.ShouldBindJSON(&selectResearch)
	selectResearch.SelectOwner = getUserName(c)
	if err := service.CreateSelectResearch(selectResearch); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags SelectResearch
// @Summary 删除SelectResearch
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SelectResearch true "删除SelectResearch"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /selectResearch/deleteSelectResearch [delete]
func DeleteSelectResearch(c *gin.Context) {
	var selectResearch model.SelectResearch
	_ = c.ShouldBindJSON(&selectResearch)
	if err := service.DeleteSelectResearch(selectResearch); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags SelectResearch
// @Summary 批量删除SelectResearch
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SelectResearch"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /selectResearch/deleteSelectResearchByIds [delete]
func DeleteSelectResearchByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteSelectResearchByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// @Tags SelectResearch
// @Summary 更新SelectResearch
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SelectResearch true "更新SelectResearch"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /selectResearch/updateSelectResearch [put]
func UpdateSelectResearch(c *gin.Context) {
	var selectResearch model.SelectResearch
	_ = c.ShouldBindJSON(&selectResearch)
	if err := service.UpdateSelectResearch(selectResearch); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags SelectResearch
// @Summary 用id查询SelectResearch
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SelectResearch true "用id查询SelectResearch"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /selectResearch/findSelectResearch [get]
func FindSelectResearch(c *gin.Context) {
	var selectResearch model.SelectResearch
	_ = c.ShouldBindQuery(&selectResearch)
	if err, reselectResearch := service.GetSelectResearch(selectResearch.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reselectResearch": reselectResearch}, c)
	}
}

// @Tags SelectResearch
// @Summary 分页获取SelectResearch列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SelectResearchSearch true "分页获取SelectResearch列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /selectResearch/getSelectResearchList [get]
func GetSelectResearchList(c *gin.Context) {
	var pageInfo request.SelectResearchSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetSelectResearchInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败", zap.Any("err", err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
